﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Net;

namespace LS.Screening.Core
{
    /// <summary>
    /// 全局Action过滤器
    /// </summary>
    public class GlobalActionFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);
            if (context.Result is ObjectResult dataResult)
            {
                var result = new ReturnObject<Object>
                {
                    Success = true,
                    Code = (int)HttpStatusCode.OK,
                    Data = dataResult.Value,
                    Message = "success"
                };
                context.Result = new JsonResult(result);
            }
        }
    }
}
